package com.jason.kotlin.singleton

/**
 *
 * @Author: Jason
 * @Date: 2017/7/23
 * @Time: 21:10
 */

class LazyThreadSafeDoubleCheck private constructor() {

    companion object {
        val instance by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            LazyThreadSafeDoubleCheck()
        }

        private @Volatile var instance2:LazyThreadSafeDoubleCheck? =null

        fun get():LazyThreadSafeDoubleCheck {
            if (instance2 == null) {
                synchronized(this) {
                    if (instance2 == null) {
                        instance2 = LazyThreadSafeDoubleCheck()
                    }
                }
            }

            return instance2!!
        }

    }
}